<?php include 'header.php' ?>
<?php
include 'mySQLConnect.php';

$id = $_GET['id'];
$sql3 = "SELECT p.id as 'id_product', c.id as 'id_cat', c.cat_name, p.name, p.price, " .
    "p.ime_product, p.short_desc, p.description, p.image_url, p.fac FROM  product p" .
    " join category c on p.cat_id = c.id WHERE p.id = '$id'";

$result3 = mysql_query($sql3);

$cat_id = "";
$cat_name = "";
$price = "";
$image_url = "";
$ime = "";
$short_desc = "";
$description = "";
$name = "";

while ($row3 = mysql_fetch_array($result3)) {
    $image_url = $row3['image_url'];

    if (strpos($image_url, '../') !== false) {
        $image_url = substr($image_url, 3);
    }

    $pri = $row3['price'];
    $price = ($row3['price']);
    $temp = "";
    $price = strrev($price);
    while (strlen($price) >= 4) {
        $temp = $temp . substr($price, 0, 3) . '.';
        $price = substr($price, 3);
    }

    if (strlen($price) == 0) {
        $price = strrev($temp);
    } else {
        $price = strrev($price) . strrev($temp);
    }

    $cat_name = urldecode($row3['cat_name']);
    $ime = $row3['ime_product'];
    $short_desc = urldecode($row3['short_desc']);
    $description = urldecode($row3['description']);
    $name = urldecode($row3['name']);
    $cat_id = $row3['id_cat'];
    $fac = urldecode($row3['fac']);
}

include 'mySQLClose.php';
?>
    <div class="container_12 primary_content_wrap clearfix">
        <div class="grid_8 right" id="content">
            <div class="bc-wrap">
                <div id="breadcrumb"><a href="index.php" class="home">Trang chủ</a>
                    › <a href="product.php">Sản phẩm</a> › <a
                        href="searchProduct.php?type=cate&cat_id=<?php echo $cat_id ?>"><?php echo $cat_name ?></a>
                </div>
            </div>
            <div class="post-361 product type-product status-publish hentry" id="post-361">
                <div class="images">
                    <div id="holder" class="img-holder">
                        <a id="prettyLink" href="<?php echo $image_url ?>" rel="prettyPhoto" class="item1">
                            <img alt="" src="<?php echo $image_url ?>" style="width: 263px; height: auto;"></a>
                    </div>
                </div>
                <div class="summary">
                    <h2 class="product_title added"><?php echo $name ?></h2>

                    <div class="attributes">
                        <div class="product-price"><span class="label">Mã số: </span><?php echo $ime ?></div>
                        <div class="product-price"><span class="label">Giá: </span><?php echo $price ?> VND</div>
                        <div class="product-price"><span class="label">Nhà sản xuất: </span><?php echo $fac ?></div>
                        <div class="product-price"><span class="label">Bộ sản phẩm: </span>
                            <p style="font-family:times new roman"><?php echo $short_desc ?></p></div>
                    </div>
                    <div class="share-buttons">
                        <span style="display: inline-block;padding: 8px;">Mua hàng</span> <a href="javascript:addCart('<?php echo $ime ?>','<?php echo $name ?>','<?php echo $pri ?>')">
                            <img src="images/cart.png">
                        </a>
                    </div>
                </div>
                <div class="clear"></div>
                <div>
                    <h3>Mô tả sản phẩm</h3>
                    <div id="tab-description" class="panel" style="display: block;">
                        <?php echo $description ?>
                    </div>
                    <div id="tab-reviews" class="panel">
                        <div id="reviews">
                            <div class="fb-comments"
                                 data-href="http://localhost/laptop"
                                 data-width="578" data-num-posts="10"></div>
                            <div class="clear"></div>
                        </div>
                    </div>
                </div>
                <div class="related products"><h2>Sản Phẩm Liên Quan</h2>
                    <ul class="products">
                        <?php include 'mySQLConnect.php';

                        $sql3 = "SELECT * FROM product WHERE id <> '$id' AND cat_id = '$cat_id' ORDER BY date DESC LIMIT 0,3";

                        $result3 = mysql_query($sql3);
                        $count = 0;
                        while ($row3 = mysql_fetch_array($result3)) {
                            $count++;
                            $image_url = $row3['image_url'];

                            if (strpos($image_url, '../') !== false) {
                                $image_url = substr($image_url, 3);
                            }

                            $price = ($row3['price']);
                            if (strlen($price) > 4) {
                                $price = strrev($price);
                                $price = strrev(substr($price, 3)) . "." . "000";
                            }

                            if ($count == 1) {
                                ?>
                                <li class="product first">
                                    <div class="product-inner">
                                        <div class="product-image-wrap"><a class="product-image"
                                                                           href="detailProduct.php?id=<?php echo $row3['id'] ?>"><img
                                                    width="305" height="305" alt=""
                                                    class="attachment-shop_small wp-post-image"
                                                    src="<?php echo $image_url ?>"
                                                    style="opacity: 1;"></a></div>
                                        <div class="caption">
                                            <h3 class="title"><a class="product-info"
                                                                 href="detailProduct.php?id=<?php echo $row3['id'] ?>"><?php echo urldecode($row3['name']) ?></a>
                                            </h3>
                                            <span class="price"><?php echo $price ?> VND</span> <a class="button"
                                                                                                   href="detailProduct.php?id=<?php echo $row3['id'] ?>">Chi
                                                tiết</a>
                                        </div>
                                    </div>
                                </li>
                            <?php } else if ($count == 2) { ?>

                                <li class="product ">
                                    <div class="product-inner">
                                        <div class="product-image-wrap"><a class="product-image"
                                                                           href="detailProduct.php?id=<?php echo $row3['id'] ?>"><img
                                                    width="305" height="305" alt=""
                                                    class="attachment-shop_small wp-post-image"
                                                    src="<?php echo $image_url ?>"
                                                    style="opacity: 1;"></a></div>
                                        <div class="caption">
                                            <h3 class="title"><a class="product-info"
                                                                 href="detailProduct.php?id=<?php echo $row3['id'] ?>"><?php echo urldecode($row3['name']) ?></a>
                                            </h3>
                                            <span class="price"><?php echo $price ?> VND</span> <a class="button"
                                                                                                   href="detailProduct.php?id=<?php echo $row3['id'] ?>">Chi
                                                tiết</a>
                                        </div>
                                    </div>
                                </li>
                            <?php } else { ?>
                                <li class="product last">
                                    <div class="product-inner">
                                        <div class="product-image-wrap"><a class="product-image"
                                                                           href="detailProduct.php?id=<?php echo $row3['id'] ?>"><img
                                                    width="305" height="305" alt=""
                                                    class="attachment-shop_small wp-post-image"
                                                    src="<?php echo $image_url ?>"
                                                    style="opacity: 1;"></a></div>
                                        <div class="caption">
                                            <h3 class="title"><a class="product-info"
                                                                 href="detailProduct.php?id=<?php echo $row3['id'] ?>"><?php echo urldecode($row3['name']) ?></a>
                                            </h3>
                                            <span class="price"><?php echo $price ?> VND</span><a class="button"
                                                                                                  href="detailProduct.php?id=<?php echo $row3['id'] ?>">Chi
                                                tiết</a>
                                        </div>
                                    </div>
                                </li>
                            <?php
                            }
                        }
                        include 'mySQLClose.php';?>
                    </ul>
                    <div class="clear"></div>
                </div>
            </div>
        </div>
        <aside class="grid_4" id="sidebar">
            <?php include 'rightMenu.php'; ?>
        </aside>
    </div>
<?php include 'footer.php' ?>